package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Objects;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.AppFavorite;
import com.ruoyi.system.mapper.AppFavoriteMapper;
import com.ruoyi.system.service.IAppFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AppArtifactMapper;
import com.ruoyi.system.domain.AppArtifact;
import com.ruoyi.system.service.IAppArtifactService;

/**
 * 文物信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@Service
public class AppArtifactServiceImpl implements IAppArtifactService 
{
    @Autowired
    private AppArtifactMapper appArtifactMapper;
    @Autowired
    private AppFavoriteMapper appFavoriteMapper;

    /**
     * 查询文物信息
     * 
     * @param artifactId 文物信息主键
     * @return 文物信息
     */
    @Override
    public AppArtifact selectAppArtifactByArtifactId(Long artifactId)
    {
        AppArtifact appArtifact =  appArtifactMapper.selectAppArtifactByArtifactId(artifactId);
        AppFavorite appFavorite = appFavoriteMapper.getFavoriteByUserIdAndArtifactId(artifactId,SecurityUtils.getLoginAppUser().getUserId());
        appArtifact.setFavoriteId(Objects.nonNull(appFavorite) ? appFavorite.getFavoriteId() : null);
        return appArtifact;
    }

    /**
     * 查询文物信息列表
     * 
     * @param appArtifact 文物信息
     * @return 文物信息
     */
    @Override
    public List<AppArtifact> selectAppArtifactList(AppArtifact appArtifact)
    {
        return appArtifactMapper.selectAppArtifactList(appArtifact);
    }

    /**
     * 新增文物信息
     * 
     * @param appArtifact 文物信息
     * @return 结果
     */
    @Override
    public int insertAppArtifact(AppArtifact appArtifact)
    {

        appArtifact.setCreateTime(DateUtils.getNowDate());
        return appArtifactMapper.insertAppArtifact(appArtifact);
    }

    /**
     * 修改文物信息
     * 
     * @param appArtifact 文物信息
     * @return 结果
     */
    @Override
    public int updateAppArtifact(AppArtifact appArtifact)
    {
        appArtifact.setUpdateTime(DateUtils.getNowDate());
        return appArtifactMapper.updateAppArtifact(appArtifact);
    }

    /**
     * 批量删除文物信息
     * 
     * @param artifactIds 需要删除的文物信息主键
     * @return 结果
     */
    @Override
    public int deleteAppArtifactByArtifactIds(Long[] artifactIds)
    {
        return appArtifactMapper.deleteAppArtifactByArtifactIds(artifactIds);
    }

    /**
     * 删除文物信息信息
     * 
     * @param artifactId 文物信息主键
     * @return 结果
     */
    @Override
    public int deleteAppArtifactByArtifactId(Long artifactId)
    {
        return appArtifactMapper.deleteAppArtifactByArtifactId(artifactId);
    }
}
